package com.yangcangclub.commons.utils;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;

/**
 * 自动生成bean，仅供开发时使用，<br>
 * 严禁在测试和生产环境的业务代码里上使用，否则后果自负
 */
public class DBHelper {
//    public static final String url = "jdbc:mysql://120.76.114.137:3306/likesharing1?useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull";
//    public static final String name = "com.mysql.jdbc.Driver";
//    public static final String user = "root";
//    public static final String password = "FSse647sf#fJUYX*%df!s";
    
    public static final String url = "jdbc:mysql://192.168.0.89:3306/traveler99?useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&tinyInt1isBit=false";
    public static final String name = "com.mysql.jdbc.Driver";
    public static final String user = "root";
    public static final String password = "manager1";    
    

    public Connection conn = null;
    public PreparedStatement pst = null;

    public DBHelper() {
    }
    
    public Connection getConn(){
        try {
            Class.forName(name);//指定连接类型
            return DriverManager.getConnection(url, user, password);//获取连接
        } catch (SQLException e) {
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
        return null;
    }
    
    public DBHelper(String sql) {
        try {
            Class.forName(name);//指定连接类型
            conn = DriverManager.getConnection(url, user, password);//获取连接
            pst = conn.prepareStatement(sql);//准备执行语句
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    
    

    public void close() {
        try {
            this.conn.close();
            this.pst.close();
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
